//
//  HouseTypeInfoBottomBarView.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/3/26.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "HouseTypeInfoBottomBarView.h"
#import "Masonry.h"

@interface HouseTypeInfoBottomBarView()

@property (nonatomic, strong) UILabel *numberIndicatorLabel;
@property (nonatomic, strong) UILabel *attentionLabel;
@property (nonatomic, strong) UIImageView *houseCountImageView;
@property (nonatomic, strong) UIImageView *attentionImageView;
@end

@implementation HouseTypeInfoBottomBarView
@synthesize houseCountLabel = _houseCountLabel;
#pragma mark - Initialize
- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self loadHouseTypeInfoBottomBarView];
    }
    return self;
}
#pragma mark - Private
- (void)loadHouseTypeInfoBottomBarView{
    UIView *barView = [UIView new];
    barView.backgroundColor = LineColor222;
    UIView *attentionBackView = [UIView new];
    UIView *houseCountBackView = [UIView new];
    
    [self addSubview:attentionBackView];
    [self addSubview:houseCountBackView];
    [self addSubview:barView];
    
    [barView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
        make.height.mas_equalTo(1);
    }];
    
    [attentionBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self);
    }];
    [self.numberIndicatorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.left.equalTo(attentionBackView.right);
        make.width.equalTo(attentionBackView);
    }];
    [houseCountBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.left.equalTo(self.numberIndicatorLabel.right);
        make.right.equalTo(self);
        make.width.equalTo(self.numberIndicatorLabel);
    }];
    [self loadAttentionViewWithBackView:attentionBackView];
    [self loadHouseCountViewWithBackView:houseCountBackView];
}

- (void)loadAttentionViewWithBackView:(UIView *)backView{
    [backView addSubview:self.attentionImageView];
    [backView addSubview:self.attentionLabel];
    
    [self.attentionImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backView).offset(10);
        make.centerY.equalTo(backView);
        make.width.equalTo(self.attentionImageView.height);
        make.height.equalTo(backView).multipliedBy(0.4);
    }];
    
    [self.attentionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.attentionImageView.mas_right).offset(5);
        make.top.bottom.equalTo(self.attentionImageView);
        make.right.equalTo(backView);
    }];
    
}

- (void)loadHouseCountViewWithBackView:(UIView *)backView{
    [backView addSubview:self.houseCountImageView];
    [backView addSubview:self.houseCountLabel];
    
    [self.houseCountImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backView);
        make.width.equalTo(self.houseCountImageView.height);
        make.height.equalTo(backView).multipliedBy(0.4);
    }];
    [self.houseCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.houseCountImageView.mas_right).offset(5);
        make.top.bottom.equalTo(self.houseCountImageView);
        make.right.equalTo(backView).offset(-TenOffsetViewMargin);
    }];
}

#pragma mark - Getter
- (UILabel *)attentionLabel{
    
    if (_attentionLabel == nil) {
        _attentionLabel = [UILabel new];
        _attentionLabel.font = TextFont14;
        _attentionLabel.textColor = TextColor80;
    }
    return _attentionLabel;
}

- (UILabel *)numberIndicatorLabel{
    
    if (_numberIndicatorLabel == nil) {
        _numberIndicatorLabel = [UILabel new];
        _numberIndicatorLabel.font = TextFont14;
        _numberIndicatorLabel.textColor = TextColor80;
        _numberIndicatorLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_numberIndicatorLabel];
    }
    return _numberIndicatorLabel;
}

- (UILabel *)houseCountLabel{
    
    if (_houseCountLabel == nil) {
        _houseCountLabel = [UILabel new];
        _houseCountLabel.font = TextFont14;
        _houseCountLabel.textColor = TextColor80;
    }
    return _houseCountLabel;
}

- (UIImageView *)houseCountImageView{
    
    if (_houseCountImageView == nil) {
        _houseCountImageView = [UIImageView new];
        _houseCountImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _houseCountImageView;
}

- (UIImageView *)attentionImageView{

    if (_attentionImageView == nil) {
        _attentionImageView = [UIImageView new];
        _attentionImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _attentionImageView;
}

#pragma mark - Setter
- (void)setBarModel:(HouseTypeInfoBottomBarModel *)barModel{
    if (barModel.selectedLayoutNum != 0) {
        self.numberIndicatorLabel.text = [NSString stringWithFormat:@"%ld/%ld",barModel.selectedLayoutNum,barModel.totalLayoutNum];
    }
    self.attentionLabel.text = [NSString stringWithFormat:@"关注(%ld)",barModel.attentionNum];
    self.houseCountLabel.text = [NSString stringWithFormat:@"房源(%ld)",barModel.totalHouseNum];
    self.houseCountLabel.tag = barModel.totalHouseNum;
    [self.attentionImageView setIconWithKey:@"layoutFollowIcon" withPlaceHolderString:DefaultNetImage1To1];
    [self.houseCountImageView setIconWithKey:@"layoutHousesIcon" withPlaceHolderString:DefaultNetImage1To1];
}

@end
